import java.util.*;

class CinemaManagementSystem{
    private Map<String, User>users;
    private List<Movie>movies;
    private List<Screening>screenings;
    private List<Ticket>tickets;
    Scanner scanner=new Scanner(System.in);

    private void initializeSystem(){
        users=new HashMap<>();
        movies=new ArrayList<>();
        screenings=new ArrayList<>();
        tickets=new ArrayList<>();
        Admin admin=new Admin("admin001","admin","ynuinfo#777","00000000000",users,movies,screenings,tickets);
        users.put(admin.getUserId(),admin);
    }

    //登录前界面
    public void mainMenu(){
        System.out.println("影院初始化中......");
        initializeSystem();
        while (true){
            System.out.println("===== 万东电影院管理系统 =====");
            System.out.println("1. 登录");
            System.out.println("2. 退出系统");
            System.out.println("（提示：退出系统后将清空影院所有数据，且无法恢复！）");
            System.out.print("请选择:");

            try{
                int choice=Integer.parseInt(scanner.nextLine());
                switch(choice){
                    case 1:
                        login();
                        break;
                    case 2:
                        System.out.println("感谢使用影院管理系统!");
                        return;
                    default:
                        System.out.println("无效选择，请重新输入");
                }
            } catch(NumberFormatException e){
                System.out.println("请输入有效数字");
            }
        }
    }

    //登录界面
    private void login(){
        System.out.println("===== 登录系统 =====");
        System.out.println("请选择您的身份：");
        System.out.println("1. 管理员");
        System.out.println("2. 经理");
        System.out.println("3. 前台");
        int choice=Integer.parseInt(scanner.nextLine());
        UserType userType;
        try {
            switch (choice) {
                case (1):
                    userType = UserType.ADMIN;
                    break;
                case (2):
                    userType = UserType.MANAGER;
                    break;
                case (3):
                    userType = UserType.FRONT_DESK;
                    break;
                default:
                    System.out.println("无效选择");
                    return;
            }
        } catch (NumberFormatException|InputMismatchException e) {
            System.out.println("请输入有效数字");
            return;
        }
        System.out.println("用户名：");
        String username=scanner.nextLine();
        System.out.println("密码：");
        String password=scanner.nextLine();
        for (User user:users.values()){
            if (user.getUsername().equals(username)&&user.checkPassword(password)){
                if(!user.userType.equals(userType)){
                    System.out.println("用户身份错误");
                    return;
                }
                System.out.println("登录成功!欢迎," + username);
                user.menu();
                return;
            }
        }
        System.out.println("登录失败: 用户名或密码错误");
    }
}

class Main{
    public static void main(String[] args) {
        CinemaManagementSystem cinemaManagementSystem=new CinemaManagementSystem();
        cinemaManagementSystem.mainMenu();
    }
}